﻿<common:LayoutAwarePage x:ConnectionId='1'
    x:Name="pageRoot"
    x:Class="ContentApp.Base.View.MainPage"
    DataContext="{Binding MainViewModel, Source={StaticResource Locator}}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:ContentApp"
    xmlns:common="using:ContentApp.Base.Common"
    xmlns:utils="using:ContentApp.Base.Utils"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:ad="using:Microsoft.Advertising.WinRT.UI"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
                            
    NavigationCacheMode="Enabled">

    <Page.Resources>
        <CollectionViewSource
            x:Name="groupedItemsViewSource"
            Source="{Binding Sections}"
            IsSourceGrouped="true" />
        <utils:GroupInfoListToGroupHeaderButtonStyleConverter x:Key="GroupInfoListToGroupHeaderButtonStyleConverter" />
        <utils:HubItemTemplateSelector x:Key="HubItemTemplateSelector">
            <utils:HubItemTemplateSelector.HeroImageTemplate>
                <DataTemplate>
                    <StackPanel>
                        <Image Source="{Binding Content.Url}" Stretch="None" VerticalAlignment="Top" />
                        <TextBlock FontSize="12" Text="{Binding Content.LegalNotice}" Margin="0,10,0,0" TextWrapping="Wrap" MaxWidth="300" HorizontalAlignment="Left" />
                    </StackPanel>
                </DataTemplate>
            </utils:HubItemTemplateSelector.HeroImageTemplate>
            <utils:HubItemTemplateSelector.IntroTemplate>
                <DataTemplate>
                    <common:RichTextColumns VerticalAlignment="Top" Margin="-40,0,0,0" >
                        <RichTextBlock Width="400" Style="{StaticResource ItemRichTextStyle}">
                            <Paragraph>
                                <Run Text="{Binding Content}" />
                            </Paragraph>
                        </RichTextBlock>
                        <common:RichTextColumns.ColumnTemplate>
                            <DataTemplate>
                                <RichTextBlockOverflow Width="400" Margin="40,0,0,0">
                                    <RichTextBlockOverflow.RenderTransform>
                                        <TranslateTransform X="-1" Y="4"/>
                                    </RichTextBlockOverflow.RenderTransform>
                                </RichTextBlockOverflow>
                            </DataTemplate>
                        </common:RichTextColumns.ColumnTemplate>
                    </common:RichTextColumns>
                </DataTemplate>
            </utils:HubItemTemplateSelector.IntroTemplate>
            <utils:HubItemTemplateSelector.ImageResultTemplate>
                <DataTemplate>
                    <GridView x:ConnectionId='5' ItemsSource="{Binding Content}" Margin="0,6,0,0" SelectionMode="None" IsSwipeEnabled="False" IsItemClickEnabled="True"                                     Style="{StaticResource NoScrollGridViewStyle}" ItemTemplate="{StaticResource ImageResultTemplate}">
                        <GridView.ItemsPanel>
                            <ItemsPanelTemplate>
                                <VariableSizedWrapGrid>
                                    <VariableSizedWrapGrid.ChildrenTransitions>
                                        <TransitionCollection>
                                            <EntranceThemeTransition/>
                                            <AddDeleteThemeTransition />
                                        </TransitionCollection>
                                    </VariableSizedWrapGrid.ChildrenTransitions>
                                </VariableSizedWrapGrid>
                            </ItemsPanelTemplate>
                        </GridView.ItemsPanel>
                    </GridView>
                </DataTemplate>
            </utils:HubItemTemplateSelector.ImageResultTemplate>
            <utils:HubItemTemplateSelector.WebResultTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <GridView x:ConnectionId='6' ItemsSource="{Binding Content}" Margin="0,6,0,0" SelectionMode="None" IsSwipeEnabled="False" IsItemClickEnabled="True"                                   Style="{StaticResource NoScrollGridViewStyle}" ItemTemplate="{StaticResource WebResultTemplate}">
                            <GridView.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <VariableSizedWrapGrid>
                                        <VariableSizedWrapGrid.ChildrenTransitions>
                                            <TransitionCollection>
                                                <EntranceThemeTransition/>
                                                <AddDeleteThemeTransition />
                                            </TransitionCollection>
                                        </VariableSizedWrapGrid.ChildrenTransitions>
                                    </VariableSizedWrapGrid>
                                </ItemsPanelTemplate>
                            </GridView.ItemsPanel>
                        </GridView>
                        <ad:AdControl Grid.Column="1" AdUnitId="{StaticResource AdUnitIdFullscreen}" ApplicationId="{StaticResource AdApplicationId}" Width="160" Height="600" Margin="20,0,0,0" VerticalAlignment="Top" Visibility="{Binding MainViewModel.IsZoomedIn, Source={StaticResource Locator}, Converter={StaticResource BooleanToVisibilityConverter}}">
                            <ad:AdControl.RenderTransform>
                                <CompositeTransform TranslateY="-29" />
                            </ad:AdControl.RenderTransform>
                        </ad:AdControl>
                    </Grid>
                </DataTemplate>
            </utils:HubItemTemplateSelector.WebResultTemplate>
            <utils:HubItemTemplateSelector.ChapterTemplate>
                <DataTemplate>
                    <common:RichTextColumns VerticalAlignment="Top" Margin="1,0,0,0" >
                        <RichTextBlock x:ConnectionId='7' Width="400" Style="{StaticResource ItemRichTextStyle}"                               />
                        <common:RichTextColumns.ColumnTemplate>
                            <DataTemplate>
                                <RichTextBlockOverflow Width="400" Margin="40,0,0,0">
                                    <RichTextBlockOverflow.RenderTransform>
                                        <TranslateTransform X="-1" Y="4"/>
                                    </RichTextBlockOverflow.RenderTransform>
                                </RichTextBlockOverflow>
                            </DataTemplate>
                        </common:RichTextColumns.ColumnTemplate>
                    </common:RichTextColumns>
                </DataTemplate>
            </utils:HubItemTemplateSelector.ChapterTemplate>
        </utils:HubItemTemplateSelector>
        <utils:HubItemTemplateSelector x:Key="HubItemSnappedTemplateSelector">
            <utils:HubItemTemplateSelector.HeroImageTemplate>
                <DataTemplate>
                    <StackPanel>
                        <Image Source="{Binding Content.Url}" Stretch="Uniform" VerticalAlignment="Top" Margin="4,0" />
                        <TextBlock FontSize="12" Text="{Binding Content.LegalNotice}" Margin="4,10,4,0" TextWrapping="Wrap" MaxWidth="280" HorizontalAlignment="Left" />
                    </StackPanel>
                </DataTemplate>
            </utils:HubItemTemplateSelector.HeroImageTemplate>
            <utils:HubItemTemplateSelector.IntroTemplate>
                <DataTemplate>
                    <RichTextBlock Style="{StaticResource ItemRichTextStyle}" Margin="4,0">
                        <Paragraph>
                            <Run Text="{Binding Content}" />
                        </Paragraph>
                    </RichTextBlock>
                </DataTemplate>
            </utils:HubItemTemplateSelector.IntroTemplate>
            <utils:HubItemTemplateSelector.ImageResultTemplate>
                <DataTemplate>
                    <ListView x:ConnectionId='2' ItemsSource="{Binding Content}" SelectionMode="None" IsSwipeEnabled="False" IsItemClickEnabled="True"                                     Style="{StaticResource NoScrollListViewStyle}" ItemTemplate="{StaticResource ImageResultSnappedTemplate}" >
                        <ListView.ItemsPanel>
                            <ItemsPanelTemplate>
                                <StackPanel>
                                    <StackPanel.ChildrenTransitions>
                                        <TransitionCollection>
                                            <EntranceThemeTransition/>
                                            <AddDeleteThemeTransition />
                                        </TransitionCollection>
                                    </StackPanel.ChildrenTransitions>
                                </StackPanel>
                            </ItemsPanelTemplate>
                        </ListView.ItemsPanel>
                    </ListView>
                </DataTemplate>
            </utils:HubItemTemplateSelector.ImageResultTemplate>
            <utils:HubItemTemplateSelector.WebResultTemplate>
                <DataTemplate>
                    <StackPanel>
                        <ListView x:ConnectionId='3' ItemsSource="{Binding Content}" SelectionMode="None" IsSwipeEnabled="False" IsItemClickEnabled="True"                                   Style="{StaticResource NoScrollListViewStyle}" ItemTemplate="{StaticResource WebResultSnappedTemplate}">
                            <ListView.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <StackPanel>
                                        <StackPanel.ChildrenTransitions>
                                            <TransitionCollection>
                                                <EntranceThemeTransition/>
                                                <AddDeleteThemeTransition />
                                            </TransitionCollection>
                                        </StackPanel.ChildrenTransitions>
                                    </StackPanel>
                                </ItemsPanelTemplate>
                            </ListView.ItemsPanel>
                        </ListView>
                        <ad:AdControl Grid.Column="1" AdUnitId="{StaticResource AdUnitIdSnapped}" ApplicationId="{StaticResource AdApplicationId}" Width="292" Height="60" Margin="0,10,0,0" VerticalAlignment="Top" Visibility="{Binding MainViewModel.IsZoomedIn, Source={StaticResource Locator}, Converter={StaticResource BooleanToVisibilityConverter}}">
                            <ad:AdControl.RenderTransform>
                                <CompositeTransform TranslateX="-6" />
                            </ad:AdControl.RenderTransform>
                        </ad:AdControl>
                    </StackPanel>
                </DataTemplate>
            </utils:HubItemTemplateSelector.WebResultTemplate>
            <utils:HubItemTemplateSelector.ChapterTemplate>
                <DataTemplate>
                    <RichTextBlock x:ConnectionId='4' Style="{StaticResource ItemRichTextStyle}"                               Margin="4,0" />
                </DataTemplate>
            </utils:HubItemTemplateSelector.ChapterTemplate>
        </utils:HubItemTemplateSelector>
    </Page.Resources>
    
    <Grid Style="{StaticResource LayoutRootStyle}">
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <Grid x:Name="Header" Margin="117,0,0,0">
            <TextBlock x:Name="pageTitle" Text="{Binding Title}" Style="{StaticResource PageHeaderTextStyle}"/>

            <Border x:ConnectionId='13' x:Name="LegalNoticeFullscreen" Padding="20,10" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,0,40" Background="#FF666666"                                              >
                <TextBlock Text="{Binding LegalNotice}" Foreground="White" />
            </Border>
        </Grid>

        <SemanticZoom x:ConnectionId='8' Grid.Row="1" x:Name="SemanticZoomFullscreen"                                                              >
            <SemanticZoom.ZoomedInView>
                <ListView ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}" Style="{StaticResource SemanticZoomedInGridViewStyle}" ItemTemplateSelector="{StaticResource HubItemTemplateSelector}" ItemContainerStyle="{StaticResource PlainGridViewItemStyle}" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollMode="Auto" ScrollViewer.VerticalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollMode="Disabled" VerticalContentAlignment="Stretch" >
                    <ListView.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Horizontal">
                                <StackPanel.ChildrenTransitions>
                                    <TransitionCollection>
                                        <EntranceThemeTransition/>
                                        <AddDeleteThemeTransition />
                                    </TransitionCollection>
                                </StackPanel.ChildrenTransitions>
                            </StackPanel>
                        </ItemsPanelTemplate>
                    </ListView.ItemsPanel>
                    <ListView.GroupStyle>
                        <GroupStyle>
                            <GroupStyle.HeaderTemplate>
                                <DataTemplate>
                                    <Button x:ConnectionId='12'
                                                                  
                                        AutomationProperties.Name="Group Title"
                                        Visibility="{Binding ShowKey, Converter={StaticResource BooleanToVisibilityConverter}}"
                                        Style="{Binding Converter={StaticResource GroupInfoListToGroupHeaderButtonStyleConverter}}">
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock Text="{Binding Key}" Margin="0,-7,5,10" Style="{StaticResource GroupHeaderTextStyle}" />
                                            <TextBlock Text="{StaticResource ChevronGlyph}" FontFamily="Segoe UI Symbol" Margin="0,-7,0,10" Style="{StaticResource GroupHeaderTextStyle}" Visibility="{Binding Converter={StaticResource TestConverter}}"/>
                                        </StackPanel>
                                    </Button>
                                </DataTemplate>
                            </GroupStyle.HeaderTemplate>
                            <GroupStyle.Panel>
                                <ItemsPanelTemplate>
                                    <StackPanel Margin="0,0,70,0" Orientation="Horizontal" />
                                </ItemsPanelTemplate>
                            </GroupStyle.Panel>
                        </GroupStyle>
                    </ListView.GroupStyle>
                </ListView>
            </SemanticZoom.ZoomedInView>

            <SemanticZoom.ZoomedOutView>
                <GridView x:Name="groupGridView" SelectionMode="None" Padding="116,0,40,46" IsSwipeEnabled="False">
                    <GridView.ItemTemplate>
                        <DataTemplate>
                            <Grid>
                                <Grid MinWidth="250" MinHeight="165" Background="{StaticResource TileBackgroundBrush}">
                                    <TextBlock Text="{Binding Group.Key}" FontFamily="Segoe UI" FontSize="26.667" Margin="12" VerticalAlignment="Bottom" HorizontalAlignment="Left" TextWrapping="Wrap" />
                                </Grid>
                            </Grid>
                        </DataTemplate>
                    </GridView.ItemTemplate>
                    <GridView.ItemsPanel>
                        <ItemsPanelTemplate>
                            <WrapGrid Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Left"/>
                        </ItemsPanelTemplate>
                    </GridView.ItemsPanel>
                </GridView>
            </SemanticZoom.ZoomedOutView>
        </SemanticZoom>

        <SemanticZoom x:ConnectionId='9' Grid.Row="1" x:Name="SemanticZoomSnapped" Visibility="Collapsed" ScrollViewer.HorizontalScrollMode="Disabled"                                                              >
            <SemanticZoom.ZoomedInView>
                <ListView ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}" Style="{StaticResource SemanticZoomedInSnappedGridViewStyle}" ItemTemplateSelector="{StaticResource HubItemSnappedTemplateSelector}" ItemContainerStyle="{StaticResource PlainGridViewItemStyleSnapped}" >
                    <ListView.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel>
                                <StackPanel.ChildrenTransitions>
                                    <TransitionCollection>
                                        <EntranceThemeTransition/>
                                        <AddDeleteThemeTransition />
                                    </TransitionCollection>
                                </StackPanel.ChildrenTransitions>
                            </StackPanel>
                        </ItemsPanelTemplate>
                    </ListView.ItemsPanel>
                    <ListView.GroupStyle>
                        <GroupStyle>
                            <GroupStyle.HeaderTemplate>
                                <DataTemplate>
                                    <Button x:ConnectionId='11'
                                                                  
                                        AutomationProperties.Name="Group Title"
                                        Visibility="{Binding ShowKey, Converter={StaticResource BooleanToVisibilityConverter}}"
                                        Style="{Binding Converter={StaticResource GroupInfoListToGroupHeaderButtonStyleConverter}}">
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock Text="{Binding Key}" Margin="3,-7,5,10" Style="{StaticResource GroupHeaderTextStyle}" TextWrapping="Wrap" />
                                            <TextBlock Text="{StaticResource ChevronGlyph}" FontFamily="Segoe UI Symbol" Margin="0,-7,0,10" Style="{StaticResource GroupHeaderTextStyle}" Visibility="{Binding Converter={StaticResource TestConverter}}"/>
                                        </StackPanel>
                                    </Button>
                                </DataTemplate>
                            </GroupStyle.HeaderTemplate>
                            <GroupStyle.Panel>
                                <ItemsPanelTemplate>
                                    <StackPanel Margin="0,0,0,20" />
                                </ItemsPanelTemplate>
                            </GroupStyle.Panel>
                        </GroupStyle>
                    </ListView.GroupStyle>
                </ListView>
            </SemanticZoom.ZoomedInView>

            <SemanticZoom.ZoomedOutView>
                <ListView x:Name="groupGridViewSnapped" SelectionMode="None" Padding="16,0" IsSwipeEnabled="False">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <Grid>
                                <Grid Width="280" Height="50" Background="{StaticResource TileBackgroundBrush}">
                                    <TextBlock Text="{Binding Group.Key}" FontFamily="Segoe UI" FontSize="14.667" Margin="12" VerticalAlignment="Bottom" HorizontalAlignment="Left" TextWrapping="Wrap" />
                                </Grid>
                            </Grid>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </SemanticZoom.ZoomedOutView>
        </SemanticZoom>

        <Border x:ConnectionId='10' x:Name="LegalNoticeSnapped" Padding="20,10" Grid.Row="2" Background="#FF666666" Visibility="Collapsed"                                              >
            <TextBlock Text="{Binding LegalNotice}" Foreground="White" />
        </Border>
        
        <ProgressBar IsIndeterminate="True" Visibility="{Binding IsLoading, Converter={StaticResource BooleanToVisibilityConverter}}" VerticalAlignment="Top" Margin="0,10,0,0" />

        <VisualStateManager.VisualStateGroups>

            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>
                <VisualState x:Name="FullScreenPortrait" />
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="Header">
                        	<DiscreteObjectKeyFrame KeyTime="0">
                        		<DiscreteObjectKeyFrame.Value>
                        			<Thickness>19,0,0,0</Thickness>
                        		</DiscreteObjectKeyFrame.Value>
                        	</DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="SemanticZoomFullscreen">
                        	<DiscreteObjectKeyFrame KeyTime="0">
                        		<DiscreteObjectKeyFrame.Value>
                        			<Visibility>Collapsed</Visibility>
                        		</DiscreteObjectKeyFrame.Value>
                        	</DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="SemanticZoomSnapped">
                        	<DiscreteObjectKeyFrame KeyTime="0">
                        		<DiscreteObjectKeyFrame.Value>
                        			<Visibility>Visible</Visibility>
                        		</DiscreteObjectKeyFrame.Value>
                        	</DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="LegalNoticeFullscreen">
                        	<DiscreteObjectKeyFrame KeyTime="0">
                        		<DiscreteObjectKeyFrame.Value>
                        			<Visibility>Collapsed</Visibility>
                        		</DiscreteObjectKeyFrame.Value>
                        	</DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="LegalNoticeSnapped">
                        	<DiscreteObjectKeyFrame KeyTime="0">
                        		<DiscreteObjectKeyFrame.Value>
                        			<Visibility>Visible</Visibility>
                        		</DiscreteObjectKeyFrame.Value>
                        	</DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</common:LayoutAwarePage>

